<%-- 
    Document   : pmMinestoneInfo
    Created on : Jul 1, 2012, 2:45:34 PM
    Author     : ThanhTai
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x"%>

<style type="text/css">
    @import url("css/general.css");
</style>
<html>
    <head>
        <script type="text/javascript">
            function SaveMembers(){
                var validate = false;
                var formList = document.forms("ChooseStaffForm");
                var projectId = '${requestScope.ProjectID}';
                var string="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>";
                string=string+"<members>";
                alert(formList.length);
                for (var i=0; i<formList.length; i++){
                    var status=formList[i].ChooseStaff.value;
                    if (status == "Check"){
                        validate = true;
                        string=string+"<member>";


                        string=string+"<memberID>";
                        string = string + "0";
                        string=string+"</memberID>";

                        string=string+"<projectID>";
                        string=string+projectId;
                        string=string+"</projectID>";

                        string=string+"<username>";
                        var projectId= formList[i].username.value;
                        string=string+projectId;
                        string=string+"</username>";

                        string=string+"<status>";
                        string=string+"on-going";
                        string=string+"</status>";

                        string=string+"</member>";
                    }
                }
                string=string+"</members>";
                if (validate)
                {
                    if(window.ActiveXObject)//IE
                        xml_req = new ActiveXObject("Microsoft.XMLHTTP");
                    else if(window.XMLHttpRequest)
                        xml_req = new XMLHttpRequest();
                    else alert('no ajax support');

                    xml_req = new XMLHttpRequest();
                    xml_req.open("POST", "SaveMembersOfProject", true);
                    xml_req.setRequestHeader('Content-Type','text/xml');
                    xml_req.send(string);
                    xml_req.onreadystatechange = handleSaveMembersResponse;
                }
            }

            function handleSaveMembersResponse() {
                if (xml_req.readyState == 4) {
                    if (xml_req.status == 200) {
                        window.alert("Save Members table successfull!!");
                    }else
                        window.alert("Save Members table NOT successfull!!");
                }else {
                }
            }
        </script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Add Members Of Project Page</title>
    </head>
    <body>
        <div id="wrapper">
            <div id="header">
                <div id="user">
                    ${sessionScope.FULLNAME}, <a href="Controller?action=logout">Log out</a>
                </div>
            </div>

            <div id="body">
                <div id="title">
                    <h2 align="center">Add Members Of Project</h2>
                </div>
                <div id="content">
                    <div id="left">
                        <table id="Function Reference:" width="200px">
                            <tr>
                                <th>Main Functions:</th>
                            </tr>
                            <tr>
                                <td><a href="Controller?action=MainPage">Update Projects Information</a></td>
                            </tr>
                            <tr>
                                <td><a href="Controller?action=Assign Task to staff">Assign Task to staff</a></td>
                            </tr>
                            <tr>
                                <td><a href="Controller?action=Add Members of Project">Add Members of Project</a></td>
                            </tr>
                        </table>
                    </div>
                    <div id="right">
                        <div id="titleRight">
                        </div>
                        <div id="contenRight">
                            <input type="hidden" name="txtProjectID" value="${requestScope.ProjectID}" />
                            <h3 align="left">Select a Project
                            </h3>
                            <c:import url="xml/Projects.xml" var="xmldoc"/>
                            <c:import url="xsl/ProjectsForAddMembers.xsl" var="xsldoc"/>
                            <x:transform xml="${xmldoc}" xslt="${xsldoc}">
                            </x:transform>
                            <c:if test="${not empty requestScope.ProjectID}">
                                <h3 align="left">Add members for Project: ${requestScope.ProjectName}</h3>
                                <c:import url="xml/Users.xml" var="xmldoc1"/>
                                <c:import url="xsl/Users.xsl" var="xsldoc1"/>
                                <x:transform xml="${xmldoc1}" xslt="${xsldoc1}">
                                </x:transform>
                                <input align="middle" type="button" name="SaveMemberOfProject" value="Save" onclick="SaveMembers();" />
                            </c:if>
                        </div>
                    </div>
                </div>
            </div>
            <div id="footer">
            </div>
        </div>
    </body>
</html>
